package licode.unisop.log.client.feign.impl;

import licode.unisop.client.api.auth.AuthTokenShim;
import licode.unisop.log.client.api.CallingLogApi;
import licode.unisop.log.client.dto.CallingLogDTO;
import licode.unisop.log.client.feign.LogOpFeign;
import licode.unisop.log.client.feign.LogQueryFeign;
import licode.unisop.log.client.req.CallingLogIn;
import licode.unisop.unilite.dp.PageData;
import licode.unisop.unilite.utils.TryMethodCall;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
public class CallingLogApiFeign implements CallingLogApi {
    @Resource
    private LogQueryFeign logQueryFeign;

    @Resource
    private LogOpFeign logOpFeign;

    @Resource
    private AuthTokenShim authTokenShim;

    @Override
    public void save(CallingLogDTO callingLogDto) {
        logOpFeign.saveCallApi(authTokenShim.platformToken(""), callingLogDto);
    }

    @Override
    public void saveList(List<CallingLogDTO> callApiLogs) {

    }

    @Override
    public PageData<CallingLogDTO> query(CallingLogIn apiLogReq) {
        String token = authTokenShim.platformToken("");
        return TryMethodCall.execFeign(()->
                logQueryFeign.callApiList(token, apiLogReq));
    }
}
